package com.zryc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zryc.service.ICustomerAddrService;
import com.zryc.shop.entity.CustomerAddr;
import com.zryc.shop.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户地址表 前端控制器
 * </p>
 *
 * @author xujiajun
 * @since 2022-10-17
 */
@RestController
@RequestMapping("/Addr")
@Api(tags = "收件地址管理")
public class CustomerAddrController {
    @Autowired
    ICustomerAddrService customerAddrService;

    @GetMapping("/{addrId}")
    @ApiOperation("查询收货地址详情")
    public  CustomerAddr detail(@ApiParam(required = true,value = "地址ID") @PathVariable Integer addrId){
        return customerAddrService.getById(addrId);
    }

    @GetMapping("/ids")
    @ApiOperation("根据收件人姓名或电话查询地址ID列表")
    public List<Integer> getids(String name,String phone){
        QueryWrapper<CustomerAddr> wrapper=new QueryWrapper<>();
        wrapper.eq("reciever_name",name);
        wrapper.or();
        wrapper.eq("reciever_Phone",phone);
        List<CustomerAddr> customerAddrList=customerAddrService.list(wrapper);
        List<Integer> list=new ArrayList<>();
        for (CustomerAddr customer: customerAddrList){
            list.add(customer.getCustomerAddrId());
        }
        return list;
    }
}
